<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class CompanyAdmin extends Model
{
    use HasFactory;

    protected $appends = [
        'status_text'
    ];

    protected $fillable = ['company_id','role_id','admin_id','avatar','sex','id_card','idcard_file','entry_date','email','edu','status','post'];
    const POSTONLY = ['company_id','role_id','admin_id','avatar','sex','id_card','idcard_file','entry_date','email','edu','status','post'];
    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function getStatusTextAttribute()
    {
        return $this->status == 1 ? '启用' : '禁用';
    }

    public function company()
    {
        return $this->hasOne(Company::class,'id','company_id');
    }

    public function admin()
    {
        return $this->hasOne(Admin::class,'id','admin_id');
    }

    public function role()
    {
        return $this->hasOne(Role::class,'id','role_id');
    }


}
